<?php

namespace app\common\model;

use think\Model;


class Systemconfig extends Model
{





    // 表名
    protected $name = 'system_config';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'tab_text',
        'type_text',
    ];

    protected static function init()
    {
        self::afterInsert(function ($row) {
            $row->save(['weigh' => $row['id']]);
        });
    }

    public function getTabList()
    {
        return ['1' => __('Tab 1'), '5' => __('Tab 5')];
    }

    public function getTypeList()
    {
        // string,text,int,bool,array,datetime,date,file
        return ['1' => __('文本'), '2' => __('富文本'), '3' => __('数字'), '4' => __('开关'), '5' => __('时间'), '6' => __('日期'), '7' => __('文件'), '8' => __('图片')];
    }
    public function getTabTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['tab']) ? $data['tab'] : '');
        $list = $this->getTabList();
        return isset($list[$value]) ? $list[$value] : '';
    }
    public function getTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['type']) ? $data['type'] : '');
        $list = $this->getTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    public function acct()
    {
        return $this->belongsTo('Acct', 'acct_id', 'id', [], 'LEFT');
    }

}
